package org.tcx.core.logic.ajax;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.DynaBean;
import org.tcx.core.db.bean.TestCase;
import org.tcx.core.logic.contrl.TestCaseContrl;

public class TestCaseAction {
	public Object saveTestCase(JSON json, HttpServletRequest req,
			HttpServletResponse resp) throws IllegalAccessException, InvocationTargetException{
		TestCaseContrl contrl = new TestCaseContrl();
		TestCase testCase = new TestCase();
		testCase.setCreated(Calendar.getInstance().getTime());
		DynaBean bean =(DynaBean) JSONSerializer.toJava(json);
		BeanUtils.copyProperties(testCase, bean);
		contrl.makePersistent(testCase);
		return null;
	}
	public Object queryTestCase(JSON json, HttpServletRequest req,
			HttpServletResponse resp) throws IllegalAccessException, InvocationTargetException, IOException{
		TestCaseContrl contrl = new TestCaseContrl();
		List<TestCase> list =contrl.findAllTestCase();
		return list;
	}
}
